<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页详情修改</title>
    <link href="$!webPath/css/template.css"  rel="stylesheet" type="text/css">
    <link href="$!webPath/css/jquery-ui-1.8.22.custom.css" type=text/css rel=stylesheet>
    <script src="$!webPath/js/jquery.min.js"></script>
    <script src="$!webPath/js/jquery-1.6.2.js"></script>
    <script src="$!webPath/js/jquery-ui-1.8.21.js"></script>
    <script src="$!webPath/js/jquery.form1.js"></script>
</head>
<body>
    <div class="header_nav">
        <iframe name="content_frame" src="$!webPath/admin/nav" marginwidth=0 marginheight=0  frameborder=0 width=100% height=80/></iframe>
        <div class="cont_right"><a href="$!webPath/login">注销</a></div>
    </div>
    <div class="cont">
        <h3 class="seth">编辑</h3>
        <div class="nav_list">
            <ul id="ul_table">
                <li><a href="$!webPath/admin/introduction/introduction_list?size=10&page=0"><b>首页介绍列表</b></a></li>
                <li><a href="#" class="this"><b>编辑</b></a></li>
            </ul>
        </div>

            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="fshop_table">
                #if($!contentEntities.size()<=0)
                <form method="post" name="theForm" id="theForm"  enctype="multipart/form-data">
                    请选择要添加的类型：
                    <select id="add_type">
                        <option selected>--请选择--</option>
                        <option value="0">文章</option>
                        <option value="1">图片</option>
                        <option value="2">视频</option>
                    </select>
                    <div id="div_text" style="display: none;">
                        文章内容：<textarea class="text_edit" name="text" id="text_edit" cols="100" rows="8"></textarea><br/>
                    </div>
                    <div id="div_img" style="display: none;">
                        图片：<input type="file" id="img_edit" name="photo" style="opacity:1;position: static;" accept="image/jpg,image/jpeg,image/png"><br/>
                        <input type="hidden" name="picPath" id="picPath" value=""/>
                    </div>
                    <div id="div_video" style="display: none;">
                        视频路径：<input id="video_edit" type="text" name="videoPath" value=""/>
                    </div>
                    序列号：<input name="sequence" value="" id="squ" type="text">
                    <input name="introductionId" id="introductionId" value="" type="hidden"/>
                    <input name="save" type="button" value="提交" onclick="btnSave1()">
                </form>
                #else
                <div >
                #foreach($obj in $!contentEntities)
                <form method="post" name="theForm" id="theForm$!obj.id"  enctype="multipart/form-data">
                <tr id="del$!obj.id">
                    <td>
                        #if($!obj.introductionText && $!obj.introductionText!="")
                        <div class="get_text" style="width: 100%;">
                            #set($introductionText=$!utilsTools.transformStringNewLine("$!obj.introductionText"))
                            <textarea name="text" id="text$!obj.id" cols="100" rows="8">$!introductionText</textarea>
                        </div>

                        #elseif($!obj.introductionPicPath && $!obj.introductionPicPath!="")
                        <div class="get_img">
                        <img class="detail_img" src="$!webPath/$!obj.introductionPicPath" width="100%" height="400px"/>
                        <input type="hidden" value="$!obj.id"/>
                        修改图片：<input type="file" id="$!obj.id" name="photo" style="opacity:1;position: static;" accept="image/jpg,image/jpeg,image/png">
                            <input type="hidden" name="picPath" id="picPath$!obj.id" value=""/>
                        </div>
                        #elseif($!obj.introductionVideoPath && $!obj.introductionVideoPath!="")
                        <div class="get_video">
                        <video width="320" height="240" controls autoplay>
                            <source src="$!obj.introductionVideoPath" type="video/ogg">
                            <source src="$!obj.introductionVideoPath" type="video/mp4">
                            <source src="$!obj.introductionVideoPath" type="video/webm">
                            <object data="movie.mp4" width="320" height="240">
                                <embed width="320" height="240" src="$!obj.introductionVideoPath">
                            </object>
                        </video>
                        <br/>
                        修改视频路径：<input type="text" name="videoPath" id="vedio$!obj.id" value="$!obj.introductionVideoPath"/>
                        </div>
                        #end
                        序列号：<input type="text" name="sequence" id="sequence$!obj.id" value="$!obj.introductionSequence"/>
                        <div class="detail_event">
                            <input name="save" type="button" value="提交" onclick="btnSave('$!obj.id')">
                            <input type="hidden" name="introductionId" id="id$!obj.id" value="">
                            <input type="hidden" name="contentId" id="" value="$!obj.id">
                            <input type="hidden" value="$!obj.introductionId">
                            <input name="" type="button" value="删除" onclick="btnDel('$!obj.id')">
                            <input name="" type="button" value="添加" onclick="btnAdd()">
                        </div>
                    </td>
                </tr>
                </form>
                #end
                    <div id="div_add" style="display: none;">
                        <form method="post" name="theForm" id="theForm1"  enctype="multipart/form-data">
                            请选择要添加的类型：
                            <select id="add_type1">
                                <option selected>--请选择--</option>
                                <option value="0">文章</option>
                                <option value="1">图片</option>
                                <option value="2">视频</option>
                            </select>
                            <div id="div_text1" style="display: none;">
                                文章内容：<textarea class="text_edit" name="text" id="textarea1" cols="100" rows="8"></textarea><br/>
                            </div>
                            <div id="div_img1" style="display: none;">
                                图片：<input type="file" id="img1" name="photo" style="opacity:1;position: static;" accept="image/jpg,image/jpeg,image/png"><br/>
                                <input type="hidden" name="picPath" id="picPath1" value=""/>
                            </div>
                            <div id="div_video1" style="display: none;">
                                视频路径：<input type="text" id="videoPath1" name="videoPath" value=""/>
                            </div>
                            序列号：<input type="text" id="seq" name="sequence" value=""/>
                            <input name="introductionId" id="introductionId1" value="" type="hidden"/>
                            <input name="save" type="button" value="提交" onclick="btnSave2()">
                        </form>
                    </div>
                </div>
                #end
            </table>

    </div>
    <script>
        $(function(){
            getUrlParam = function (name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return decodeURI(r[2]); return null;
            }
            homeId=getUrlParam('homeId');
        })
        $('#add_type').change(function(){
            if($('#add_type option:selected').val()==0){
                $('#div_text').css('display','block');
                $('#div_img').css('display','none');
                $('#div_video').css('display','none');

            }else if($('#add_type option:selected').val()==1){
                $('#div_text').css('display','none');
                $('#div_img').css('display','block');
                $('#div_video').css('display','none');

            }else if($('#add_type option:selected').val()==2){
                $('#div_text').css('display','none');
                $('#div_img').css('display','none');
                $('#div_video').css('display','block');
                
            }
        })
        function btnSave1(){
            $('#picPath').val('');
            if($('#add_type option:selected').val()==0){
                if($('#text_edit').val()==''){
                    alert('请输入文章内容');
                    return false;
                }else{
                    var textarea=$('#text_edit').val();
                    $('#text_edit').val(((textarea.replace(/<(.+?)>/gi,"&lt;$1&gt;")).replace(/ /gi,"&nbsp;")).replace(/\n/gi,"<br/>"));
                    $('#div_img').remove();
                    $('#div_video').remove();
                }
            }else if($('#add_type option:selected').val()==1){
                if($('#img_edit').val()==''){
                    alert('请选择要上传的图片');
                    return false;
                }else{
                    $('#picPath').val($('#img_edit').val());
                    $('#div_video').remove();
                    $('#div_text').remove();
                }

            }else if($('#add_type option:selected').val()==2){
                if($('#video_edit').val()==''){
                    alert('请输入视频地址');
                    return false;
                }else{
                    $('#div_text').remove();
                    $('#div_img').remove();
                }
            }
            if($('#squ').val()==''){
                alert('请输入序列号');
                return false;
            }
            $('#introductionId').val(homeId);
            console.log($('#introductionId').val())
            $("#theForm").ajaxSubmit({
                url : "$!webPath/admin/introduction/contents_edit",
                //data:get_data,
                type : "post",
                success : function(data) {
                    window.location.href = "$!webPath/admin/introduction/contents_list?homeId="+homeId;
                },
                error : function(data) {
                    alert('失败');
                }
            });
        }
        function btnSave(id){
            var sequence=$('#sequence'+id).val()
            var textTitle=$('#text'+id).val() ;
            var video_input=$('#vedio'+id).val() ;
            var picPath=$('#'+id).val();
            var get_data={};
            if(textTitle!=''&&picPath==undefined&&video_input==undefined){
                $('#picPath'+id).val('');
                $('#text'+id).val(((textTitle.replace(/<(.+?)>/gi,"&lt;$1&gt;")).replace(/ /gi,"&nbsp;")).replace(/\n/gi,"<br/>"));
            }else if(textTitle==undefined&&picPath!=''&&video_input==undefined){

                $('#picPath'+id).val(picPath);
                console.log(picPath+'--'+$('#picPath'+id).val());
            }else if(textTitle==undefined&&picPath==undefined&&video_input!=''){
                $('#picPath'+id).val('');
            }else{
                alert('请填写你要修改的项');
                return false;
            }
            $('#id'+id).val(homeId);
            var form=$("#theForm"+id).attr('id');
            $('#'+form).ajaxSubmit({
                url : "$!webPath/admin/introduction/contents_edit",
                type : "post",
                success : function(data) {
                    console.log('+++'+$('#picPath'+id).val());
                    window.location.href = "$!webPath/admin/introduction/contents_list?homeId="+homeId;
                },
                error : function(data) {
                    alert('失败');
                }
            });
        }
        function btnDel(id){
            if(confirm("你确定要删除吗？")){
                $.ajax({
                    url:'$!webPath/admin/introduction/content_delete?contentId='+id,
                    type:'delete',
                    success: function () {
                        if('$!contentEntities.size()'=='0'){
                            window.location.href = "$!webPath/admin/introduction/contents_list?homeId="+homeId;
                        }
                        else{
                            $('#del'+id).remove();
                        }
                    },
                    error:function(){
                        alert('删除失败');
                    }
                })
            }
        }
        function btnAdd(){
            $('#div_add').css('display','block');
            $('#add_type1').change(function(){
                if($('#add_type1 option:selected').val()==0){
                    $('#div_text1').css('display','block');
                    $('#div_img1').css('display','none');
                    $('#div_video1').css('display','none');
                }else if($('#add_type1 option:selected').val()==1){
                    $('#div_text1').css('display','none');
                    $('#div_img1').css('display','block');
                    $('#div_video1').css('display','none');
                }else if($('#add_type1 option:selected').val()==2){
                    $('#div_text1').css('display','none');
                    $('#div_img1').css('display','none');
                    $('#div_video1').css('display','block');
                }
            })
        }
        function btnSave2(id){
            $('#picPath').val('');
            if($('#add_type option:selected').val()==0){
                if($('#texteare1').val()==''){
                    alert('请输入文章内容');
                    return false;
                }else{
                    var textarea=$('#texteare1').val();
                    $('#texteare1').val(((textarea.replace(/<(.+?)>/gi,"&lt;$1&gt;")).replace(/ /gi,"&nbsp;")).replace(/\n/gi,"<br/>"));
                    $('#div_img1').remove();
                    $('#div_video1').remove();
                }
            }else if($('#add_type option:selected').val()==1){
                if($('#img1').val()==''){
                    alert('请选择要上传的图片');
                    $('#picPath1').val('');
                    return false;
                }else{
                    $('#picPath1').val($('#img1').val());
                    $('#div_video1').remove();
                    $('#div_text1').remove();
                }
            }else if($('#add_type option:selected').val()==2){
                if($('#videoPath1').val()==''){
                    alert('请输入视频地址');
                    return false;
                }else{
                    $('#div_img1').remove();
                    $('#div_text1').remove();
                }
            }

            if($('#seq').val()==''){
                alert('请输入序列号');
                return false;
            }
            $('#introductionId1').val(homeId);
            $("#theForm1").ajaxSubmit({
                url : "$!webPath/admin/introduction/contents_edit",
                type : "post",
                //data:get_data,
                success : function(data) {
                    $('#div_add').css('display','none');
                    window.location.href = "$!webPath/admin/introduction/contents_list?homeId="+homeId;
                },
                error : function(data) {
                    alert('失败');
                }
            });
        }
    </script>
</body>
</html>